package com.woniu.supermarket.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.supermarket.entity.Category;
import com.woniu.supermarket.mapper.CategoryMapper;
import com.woniu.supermarket.service.ICategoryService;
import com.woniu.supermarket.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CategoryServiceImpl implements ICategoryService {
    @Autowired
    CategoryMapper categoryMapper;

    //分页查询
    @Override
    public PageInfo<CategoryVo> queryByPage(Integer now, Integer size, String cons) {
        PageHelper.startPage(now,size);
        List<CategoryVo> lists = categoryMapper.selectCategoryByPage(cons);
        return new PageInfo<>(lists);
    }
    //根据id查询
    @Override
    public Category queryByID(Integer id) {
        return categoryMapper.selectByPrimaryKey(id);
    }
    //添加
    public int add(Category category){
        return categoryMapper.insert(category);
    }
    //删除
    @Override
    public int remove(Integer id) {
        return categoryMapper.deleteByPrimaryKey(id);
    }
    //修改
    public int modify(Category category){
        return categoryMapper.updateByPrimaryKey(category);
    }

    @Override
    public List<Category> findAll() {
        return categoryMapper.selectAll();
    }

    @Override
    public int removeByParentId(Integer parentId) {
        return categoryMapper.deleteByParentId(parentId);
    }

    @Override
    public Category findParentCode() {
        return categoryMapper.selectParentCode();
    }

    @Override
    public List<Category> findAllParentID() {
        return categoryMapper.queryAllParentID();
    }

    @Override
    public Category findCategoryByID(int i) {
        return categoryMapper.selectByPrimaryKey(i);
    }

    @Override
    public Category findParentCodeByID(int id) {
        return categoryMapper.queryParentCodeByID(id);
    }


}
